if 倒裝句
weather = “下雨”
if weather == “下雨”
puts “宅在家裡”
end
#與以下程式相同
puts “宅在家裡” if weather == “下雨”
if...else...
weather = “下雨”
if weather == ”下雨”
puts “宅在家裡”
else
puts “出去玩!”
end
三元運算子
age = 19
if age >= 18
status = “已成年”
else
status = “未成年”
end
#與以下程式相同
status = (age > =18) ? “已成年” : “未成年”